package com.csr.csrcheck.service.impl;

import com.csr.csrcheck.mapper.RecallMapper;
import com.csr.csrcheck.pojo.Product_recall;
import com.csr.csrcheck.service.RecallService;
import com.csr.csrcheck.service.ex.CompanyException;
import com.csr.csrcheck.util.PageResult;
import com.csr.csrcheck.util.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RecallServiceImpl implements RecallService {
    @Resource
    private RecallMapper recallMapper;

    public List<Product_recall> getlist() {
        return this.recallMapper.getlist();
    }

    public PageResult getlistpage(int pageNum, int pageSize, String company_name, String product_name, String product_t_name) {
        return PageUtils.getPageResult(pageNum, pageSize, getPageInfo(pageNum, pageSize, company_name, product_name, product_t_name));
    }

    private PageInfo<Product_recall> getPageInfo(int pageNum, int pageSize, String company_name, String product_name, String product_t_name) {
        PageHelper.startPage(pageNum, pageSize);
        List<Product_recall> list = this.recallMapper.getListPage(company_name, product_name, product_t_name);
        if (list == null)
            throw new CompanyException("");
        return new PageInfo(list);
    }
}

